package leetcode;

/**
 * @param
 * @author oyz
 * @version 1.0.4
 * @description: 返回链表的中间节点,如果他有两个节点,则返回第二个节点
 * @date 2022/9/11 16:32
 */
public class Code876 {


  public ListNode middleNode(ListNode head) {
    // 用来存放数组的下标
    int index = 0;
    ListNode[] newNode = new ListNode[100];
    while(head != null){
        newNode[index++] = head;
        head = head.next;
    }
    return newNode[index/2];
  }




  public static void main(String[] args) {

  }


    public class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }

}
